package com.naiterui.ehp.ps.push.controller;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.ps.push.exception.ExceptionCodes;
import com.naiterui.ehp.ps.push.service.IDeviceTokenService;
import com.naiterui.ehp.ps.push.utils.PropertyValueConstants;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 客户端相关设备设置
 *
 * @author fangguanhong E-mail:E-mail地址
 * @version 2015-7-21 下午9:06:19 by fangguanhong
 * @Description
 */
@Controller
@RequestMapping("push/deviceSet")
@Api(tags = {SwaggerTag.PUSH + SwaggerTag.DEVICE})
public class DeviceSetController {

    private static Logger logger = LoggerFactory.getLogger(DeviceSetController.class);

    @Autowired
    private IDeviceTokenService deviceTokenService;

    @ResponseBody
    @RequestMapping("soundSwitch")
    public void soundSwitch(Long userId, String userType, Integer soundType) throws BusinessException {

        if (userId == null) {
            throw new BusinessException(ExceptionCodes.PARAM_ERROR);
        }

        if (userType == null) {
            userType = PropertyValueConstants.USER_TYPE_DOCTOR;
        }

        logger.info("用户信息userId {} userType {} 上传接收push声音 soundType {} ", userId, userType, soundType);
        this.deviceTokenService.soundSwitch(userId, userType, soundType);
    }
}
